<?php

namespace App\Http\Controllers\API;

use App\Http\Requests\API\CreateItemOrderReadAPIRequest;
use App\Http\Requests\API\UpdateItemOrderReadAPIRequest;
use App\Models\ItemOrderRead;
use App\Repositories\ItemOrderReadRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\AppBaseController;
use InfyOm\Generator\Criteria\LimitOffsetCriteria;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

/**
 * Class ItemOrderReadController
 * @package App\Http\Controllers\API
 */

class ItemOrderReadAPIController extends AppBaseController
{
    /** @var  ItemOrderReadRepository */
    private $itemOrderReadRepository;

    public function __construct(ItemOrderReadRepository $itemOrderReadRepo)
    {
        $this->itemOrderReadRepository = $itemOrderReadRepo;
    }

    /**
     * @param Request $request
     * @return Response
     *
     * @SWG\Get(
     *      path="/itemOrderReads",
     *      summary="Get a listing of the ItemOrderReads.",
     *      tags={"ItemOrderRead"},
     *      description="Get all ItemOrderReads",
     *      produces={"application/json"},
     *      @SWG\Response(
     *          response=200,
     *          description="successful operation",
     *          @SWG\Schema(
     *              type="object",
     *              @SWG\Property(
     *                  property="success",
     *                  type="boolean"
     *              ),
     *              @SWG\Property(
     *                  property="data",
     *                  type="array",
     *                  @SWG\Items(ref="#/definitions/ItemOrderRead")
     *              ),
     *              @SWG\Property(
     *                  property="message",
     *                  type="string"
     *              )
     *          )
     *      )
     * )
     */
    public function index(Request $request)
    {
        $this->itemOrderReadRepository->pushCriteria(new RequestCriteria($request));
        $this->itemOrderReadRepository->pushCriteria(new LimitOffsetCriteria($request));
        $itemOrderReads = $this->itemOrderReadRepository->all();

        return $this->sendResponse($itemOrderReads->toArray(), trans('flash.api.retrieve_success', ['model' => 'Item Order Reads']));
    }

    /**
     * @param CreateItemOrderReadAPIRequest $request
     * @return Response
     *
     * @SWG\Post(
     *      path="/itemOrderReads",
     *      summary="Store a newly created ItemOrderRead in storage",
     *      tags={"ItemOrderRead"},
     *      description="Store ItemOrderRead",
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="body",
     *          in="body",
     *          description="ItemOrderRead that should be stored",
     *          required=false,
     *          @SWG\Schema(ref="#/definitions/ItemOrderRead")
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="successful operation",
     *          @SWG\Schema(
     *              type="object",
     *              @SWG\Property(
     *                  property="success",
     *                  type="boolean"
     *              ),
     *              @SWG\Property(
     *                  property="data",
     *                  ref="#/definitions/ItemOrderRead"
     *              ),
     *              @SWG\Property(
     *                  property="message",
     *                  type="string"
     *              )
     *          )
     *      )
     * )
     */
    public function store(CreateItemOrderReadAPIRequest $request)
    {
        $input = $request->all();

        $itemOrderReads = $this->itemOrderReadRepository->create($input);

        return $this->sendResponse($itemOrderReads->toArray(), trans('flash.api.save_success', ['model' => 'Item Order Read']));
    }

    /**
     * @param int $id
     * @return Response
     *
     * @SWG\Get(
     *      path="/itemOrderReads/{id}",
     *      summary="Display the specified ItemOrderRead",
     *      tags={"ItemOrderRead"},
     *      description="Get ItemOrderRead",
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="id",
     *          description="id of ItemOrderRead",
     *          type="integer",
     *          required=true,
     *          in="path"
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="successful operation",
     *          @SWG\Schema(
     *              type="object",
     *              @SWG\Property(
     *                  property="success",
     *                  type="boolean"
     *              ),
     *              @SWG\Property(
     *                  property="data",
     *                  ref="#/definitions/ItemOrderRead"
     *              ),
     *              @SWG\Property(
     *                  property="message",
     *                  type="string"
     *              )
     *          )
     *      )
     * )
     */
    public function show($id)
    {
        /** @var ItemOrderRead $itemOrderRead */
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            return $this->sendError(trans('flash.api.not_found', ['model'=>'Item Order Read']), 404);
        }

        return $this->sendResponse($itemOrderRead->toArray(), trans('flash.api.retrieve_success', ['model' => 'Item Order Read']));
    }

    /**
     * @param int $id
     * @param UpdateItemOrderReadAPIRequest $request
     * @return Response
     *
     * @SWG\Put(
     *      path="/itemOrderReads/{id}",
     *      summary="Update the specified ItemOrderRead in storage",
     *      tags={"ItemOrderRead"},
     *      description="Update ItemOrderRead",
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="id",
     *          description="id of ItemOrderRead",
     *          type="integer",
     *          required=true,
     *          in="path"
     *      ),
     *      @SWG\Parameter(
     *          name="body",
     *          in="body",
     *          description="ItemOrderRead that should be updated",
     *          required=false,
     *          @SWG\Schema(ref="#/definitions/ItemOrderRead")
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="successful operation",
     *          @SWG\Schema(
     *              type="object",
     *              @SWG\Property(
     *                  property="success",
     *                  type="boolean"
     *              ),
     *              @SWG\Property(
     *                  property="data",
     *                  ref="#/definitions/ItemOrderRead"
     *              ),
     *              @SWG\Property(
     *                  property="message",
     *                  type="string"
     *              )
     *          )
     *      )
     * )
     */
    public function update($id, UpdateItemOrderReadAPIRequest $request)
    {
        $input = $request->all();

        /** @var ItemOrderRead $itemOrderRead */
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            return $this->sendError(trans('flash.api.not_found', ['model'=>'Item Order Read']), 404);
        }

        $itemOrderRead = $this->itemOrderReadRepository->update($input, $id);

        return $this->sendResponse($itemOrderRead->toArray(), trans('flash.api.update_success', ['model' => 'ItemOrderRead']));
    }

    /**
     * @param int $id
     * @return Response
     *
     * @SWG\Delete(
     *      path="/itemOrderReads/{id}",
     *      summary="Remove the specified ItemOrderRead from storage",
     *      tags={"ItemOrderRead"},
     *      description="Delete ItemOrderRead",
     *      produces={"application/json"},
     *      @SWG\Parameter(
     *          name="id",
     *          description="id of ItemOrderRead",
     *          type="integer",
     *          required=true,
     *          in="path"
     *      ),
     *      @SWG\Response(
     *          response=200,
     *          description="successful operation",
     *          @SWG\Schema(
     *              type="object",
     *              @SWG\Property(
     *                  property="success",
     *                  type="boolean"
     *              ),
     *              @SWG\Property(
     *                  property="data",
     *                  type="string"
     *              ),
     *              @SWG\Property(
     *                  property="message",
     *                  type="string"
     *              )
     *          )
     *      )
     * )
     */
    public function destroy($id)
    {
        /** @var ItemOrderRead $itemOrderRead */
        $itemOrderRead = $this->itemOrderReadRepository->findWithoutFail($id);

        if (empty($itemOrderRead)) {
            return $this->sendError('Item Order Read not found', 404);
        }

        $itemOrderRead->delete();

        return $this->sendResponse($id, trans('flash.api.delete_success', ['model' => 'Item Order Read']));
    }
}
